#coding:utf-8
import time, threading
from TBSpider import TBSpider
from Output import Output
from GetAllList import GetAllList
import time

#获取一个店铺的销量数据
def new_task():
    all_urls = GetAllList('lisheng.txt')
    all_url = all_urls.geturllist()
    for url in all_url:
        #print url
        spider = TBSpider(url)
        id = spider.getItemID()
        count = spider.getCount()
        print 'id:'+id+' count:'+count
        out = Output(id,count)
        out.outputdata()
        time.sleep(1)



def task():
    spider = TBSpider("https://detail.m.tmall.com/item.htm?id=39061029736")
    id = spider.getItemID()
    count = spider.getCount()
    print 'id:'+id+' count:'+count
    out = Output(id,count)
    out.outputdata()

# 新线程执行的代码:
def loop():
    print 'program start'
    while 1:
        try:
            new_task()
        except  NameError, msg:
            print  msg
            pass
        print 'now time is '+time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))+' thread running!'
        time.sleep(3)

t = threading.Thread(target=loop, name='LoopThread')
t.start()
t.join()
